import os
import sys
import rtconfig
import resource
if os.getenv('SIFLI_SDK'):
    SIFLI_SDK = os.getenv('SIFLI_SDK')
else:
    SIFLI_SDK = os.path.normpath(os.getcwd() + '/../../../../sdk')

sys.path = sys.path + [os.path.join(SIFLI_SDK, 'tools/build')]
try:
    from building import *
except:
    print('Cannot found building tool, check SIFLI_SDK')
    print(SIFLI_SDK)
    exit(-1)

SifliEnv()
os.system('msvc_setup.bat')

TARGET = rtconfig.OUTPUT_DIR + rtconfig.TARGET_NAME + '.' + rtconfig.TARGET_EXT	

rtconfig.CFLAGS += ' /IX:\\include /IY:\\ucrt /IY:\\um /IY:\\shared '
rtconfig.LFLAGS += ' /LIBPATH:L:\\ucrt\\x86  /LIBPATH:L:\\um\\x86 /LIBPATH:X:\\lib\\x86 user32.lib '    
rtconfig.EXEC_PATH='X:/bin/Hostx64/x86/'

env = Environment(TARGET_ARCH='x86',
        AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
        CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
        AR = rtconfig.AR, ARFLAGS = '-rc',
        LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)

# prepare building environment
env.PrependENVPath('PATH', 'X:/bin/Hostx64/x64/')

objs = PrepareBuilding(env)

# make a building
DoBuilding(TARGET, objs)

